﻿
function reloadGrid() {
    $('#tSortable').dataTable({
        "iDisplayLength": 5,
        "aLengthMenu": [5, 10, 25, 50, 100],
        "sPaginationType": "full_numbers",
        "iSortingCols": "STT"
    });
}


function Success(data) {
    if (data == "exist") {
        $.topAlertPopup({ "text": "Tên bị trùng", "typeAlert": "success" });
    }
    else {
        if (data != "") {
            $.topAlertPopup({ "text": "Cập nhật thành công", "typeAlert": "success" });
            $('#ID').val(data.ID);
            $('#Name').val(data.Name);
            $('#NameEN').val(data.Name);
            $('#Note').val(data.Note);
            $('#NoteEN').val(data.NoteEN);
            $('#TourTyoeID').val(data.TourTyoeID);
            $('#DayAmount').val(data.DayAmount);
            $('#PriceEN').val(data.PriceEN);
            $('#Price').val(data.Price);
            $('#ShortDescription').val(data.ShortDescription);
            $('#ShortDescriptionEN').val(data.ShortDescriptionEN);
            CKEDITOR.instances['FullDescription'].setData(data.FullDescription);
            CKEDITOR.instances['FullDescriptionEN'].setData(data.FullDescriptionEN);
            if (data.Active == false) {
                $('input[id=Active]').attr('checked', false);
            }
            else {
                $('input[id=Active]').attr('checked', true);
            }
            if (data.ShowHomePage == false) {
                $('input[id=ShowHomePage]').attr('checked', false);
            }
            else {
                $('input[id=ShowHomePage]').attr('checked', true);
            }

            $('#Discount').val(data.Discount);
            $('#DiscountEN').val(data.DiscountEN);


            //  $('#DiscountFrom').val(formatteddatefrom);
            // $('#DiscountTo').val(formatteddateto);

            $("#DiscountFrom").datetimepicker({ mask: true, format: 'd/m/Y H:i' });
            $("#DiscountTo").datetimepicker({ mask: true, format: 'd/m/Y H:i' });

            if (data.DiscountFrom != "" && data.DiscountFrom != null && data.DiscountTo != "" && data.DiscountTo != null) {
                var datefrom = new Date(parseInt(data.DiscountFrom.substr(6)));
                var formatteddatefrom = datefrom.getFullYear() + "-" + ("0" + (datefrom.getMonth() + 1)).slice(-2) + "-" + ("0" + datefrom.getDate()).slice(-2) + " " + datefrom.getHours() + ":" + datefrom.getMinutes();

                var dateto = new Date(parseInt(data.Discount.substr(6)));

                var formatteddateto = dateto.getFullYear() + "-" + ("0" + (dateto.getMonth() + 1)).slice(-2) + "-" + ("0" + dateto.getDate()).slice(-2) + " " + dateto.getHours() + ":" + dateto.getMinutes();

                $('#DiscountFrom').datetimepicker('setDate', formatteddatefrom);
                $('#DiscountTo').datetimepicker('setDate', formatteddateto);
            }


            //  alert(date);

            $('#Link').val(data.Link);
            $('#MetaTitle').val(data.MetaTitle);
            $('#MetaKeyword').val(data.MetaKeyword);
            $('#MetaDescription').val(data.MetaDescription);
        }
        else {
            $.topAlertPopup({ "text": "Lỗi vui lòng thử lại", "typeAlert": "error" });
        }
    }
}



$(document).ready(function () {

    $('#fileupload').fileupload({
        dataType: 'json',
        url: '/Administrator/TourManagement/UploadFiles?dir=Tours',
        autoUpload: true,
        done: function (e, data) {
            $('#image').html('<img width=\"70px\" height=\"70px\" src="/Media/Tours/' + data.result.name + '" />');

        }
    }).on('fileuploadprogressall', function (e, data) {
        var progress = parseInt(data.loaded / data.total * 100, 10);
        $('.progress .progress-bar').css('width', progress + '%');
    });


    $("#DiscountFrom").datetimepicker({format: 'd/m/Y H:i' });
    $("#DiscountTo").datetimepicker({ format: 'd/m/Y H:i' });

    CKEDITOR.replace("FullDescription", { filebrowserBrowseUrl: '/Content/Filemanager/index.html' });

    CKEDITOR.replace("FullDescriptionEN", { filebrowserBrowseUrl: '/Content/Filemanager/index.html' });

    $(".showedit").live("click", function (e) {
        var $this = $(this);
        ShowEdit(e, $this);
    });

    $(".delete").live("click", function (e) {
        var $this = $(this);
        DeleteProductAttribute(e, $this);
    });




    //********END*****************

});